pass by value
Pass by value is the most natural way to pass arguments to functions. As the name
implies, the value of a variable or expression is passed to the called function. In
the following example, three numeric and two string values are passed by value to Func().
a = Func (b%, c#+d#, f$$, a$, b$+c$)
pass by reference
Pass by reference is another way to pass arguments to functions. In other languages,
the address of a variable is passed to the called function. Since the called
function accesses the argument through this address, the calling and called function are
sharing the variable. Therefore, if the called function alters its argument, the
calling function will find the value of its variable has been changed.
Though functions can return at most one non-argument value, additional values can be
returned in pass by reference arguments. In the following statement, x#,y#,z# are
passed to Rotate() by reference so Rotate() can return three values in these variables.
From the values of object,crossSection,vertex, Rotate() computes three DOUBLE values and
assigns them to its first three arguments (which might be a#,b#,c# ). Since the calling
function passed x#,y#,z# by reference, it receives these final values of a#,b#,c# from
Rotate() in x#,y#,z#.
Rotate (@x#, @y#, @z#, object, crossSection, vertex)
implementation
Unlike other languages, arguments passed by reference are actually passed by value to the
specified function. But after the called function returns, the calling function
grabs the final value of the argument and assigns it to the original variable.
Therefore the result is the same as conventional pass by reference. The original
variable is altered in accordance with the operation of the called function. But the
native implementation is faster, supports arbitrary mixing of pass by value and pass by
reference, and works on variables in registers, which passing by address (ala C) does not.